<?php
// +----------------------------------------------------------------------
// | makePHP
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://makephp.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed BSD.(http://www.make.org/BSD-license.txt)
// +----------------------------------------------------------------------
// | Author: 叁石(sanshi) <sanshi0815@tom.com>
// | Author: 白家昌<baijc2004cn@126.com>
// +----------------------------------------------------------------------

/**
 * 功能: 公用函数
 * 创建日期:Wed Oct 29 12:04:04 CST 2008
 * 最后更新:
 * 作者: sanshi
 */

/**
 * 错误处理函数，页面跳转
 * @author sanshi
 * @param string $page  跳转页面
 * @param string $msg   提示信息
 * @param  int   $h     跳转时间
 */
function jumpPage($jump_page,$msg='',$h=0)
{
	//echo $jump_page.time();exit();
	
	//$msg = empty($msg)?'':"?msg=".base64_encode($msg);
	$msg = urlencode($msg);
	$msg = empty($msg)?'':"?msg={$msg}";
	$url=$jump_page.$msg;
	//echo $url;exit();
	if(!@header("Location:".$url))
	{
	   echo "<meta http-equiv=refresh content='{$h};url=".$url."'>";
	}
	
	exit();
}

/**
 * 错误信息处理
 * @name jumpError
 * @param  int	error_no 	错误号
  * @param  int	$jump_url 	转到的url
 * @return
 * @access public
 * @see
 * @version	1.0.0 (Wed Oct 29 11:06:28 CST 2008)
 * @author	sanshi
 */
function jumpError($error_no,$jump_url="",$is_admin=1)
{
	if($error_no<= -2000)
	{
		//采取js输出
		alertMsg($error_no,$jump_url);
	}else{
		global $error_object;
		//取得错误信息
		$msg = $error_object->getErrorMsg($error_no);
		if($is_admin)
		{
			$page = empty($jump_url)?ADMIN_HOST_PATH.'error.php':$jump_url;
		}else{
			$page = empty($jump_url)?HOST_PATH.'error.php':$jump_url;
		}
		//采取页面跳转
		jumpPage($page,$msg,$h=0);
	}
}
//信息提示，返回项目首页
function goToIndex($error_no)
{
	global $error_object;
	//取得错误信息
	$msg = $error_object->getErrorMsg($error_no);
	echo "<script>";
	echo "alert(' {$msg} ');";
	echo "window.location='".HOST_NAME."/index.php';";
	echo "</script>";
	exit();
}
//信息提示，如果给跳转页面就跳到指定页，如果不提供，直接跳转到上一页
function alertMsg($error_no,$url = '')
{
	global $error_object;
	//取得错误信息
	$msg = $error_object->getErrorMsg($error_no);
	echo "<script>";
	echo "alert(' {$msg} ');";
	echo true == empty($url) ? "history.go(-1);" :  "window.location='{$url}';";
	echo "</script>";
	exit();
}
//信息提示，如果给跳转页面就跳到指定页，如果不提供，直接跳转到上一页
function alertMsg2($msg,$url = '')
{
	echo "<script>";
	echo "alert(' {$msg} ');";
	echo true == empty($url) ? "history.go(-1);" :  "window.location='{$url}';";
	echo "</script>";
	exit();
}
function getUserIP()
{
	if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
		$user_ip=$_SERVER["HTTP_X_FORWARDED_FOR"];
	} else {
		$user_ip=$_SERVER["REMOTE_ADDR"];
	}
	return $user_ip;
}

//计算权限值 用户突破32位限制
function parse_power($user_power,$method_power)
{
	return  $user_power & $method_power;
}

/**
 * @abstract 获取合作伙伴信息
 * @param  int	icpcode 	国政通编码
 * @return array 	$icpcode_info	客户信息数组
 * @access public
 * @see 	  get_icpcode_info
 * @version	1.0.0 (Tue Dec 27 11:26:46 CST 2011)
 * @author	sanshi	 
 */
function get_icpcode_info ($icpcode)
{
	global $cli_app_info;
	return isset($cli_app_info[$icpcode]) ? $cli_app_info[$icpcode] : array();
}






?>
